package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.sky.dto.*;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.service.ShoppingCartService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderContriller")
@Slf4j
@Api(tags = "C端-订单接口")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private ShoppingCartService shoppingCartService;




    /**
     * 查询所有订单
     *
     * @param page
     * @param pageSize
     * @return
     */

    /*@GetMapping("/conditionSearch")
    @ApiOperation("查询所有订单")
    public Result<PageResult> pageResult(@RequestParam Integer page, Integer pageSize) {
        OrdersPageQueryDTO ordersPageQueryDTO = new OrdersPageQueryDTO();
        ordersPageQueryDTO.setPage(page);
        ordersPageQueryDTO.setPageSize(pageSize);
        log.info("查询所有订单:{},{}", page,pageSize);
        Page<OrderVO> ordersPage = orderService.pageAll(ordersPageQueryDTO);

        return Result.success(new PageResult(ordersPage.getTotal(), ordersPage.getResult()));
    }*/

    /**
     * 各个状态的订单数量统计
     *
     * @param
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result statistics() {
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        log.info("各个状态的订单数量统计:");

        return Result.success(orderStatisticsVO);

    }


    /**
     * 完成订单
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable Long id){
        log.info("完成订单:{}",id);
        orderService.completeById(id);
        return Result.success();
        }

    /**
     * 拒绝订单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/reiection")
    @ApiOperation("拒绝订单")
    public Result reiection(OrdersRejectionDTO ordersRejectionDTO){
        log.info("完成订单:{}",ordersRejectionDTO);
        orderService.reiection(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 取消订单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        log.info("取消订单:{}",ordersCancelDTO);
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 接单
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("接单")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        log.info("接单:{}",ordersConfirmDTO);
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 查询订单详情
     * @param
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> seleteById(@PathVariable Long id){
        log.info("查询订单详情:{}",id);
        OrderVO orderVO= orderService.getById(id);

        return Result.success(orderVO);
    }

    /**
     * 派送定单
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("派送定单")
    public Result delivery(@PathVariable Long id){
        log.info("派送定单:{}",id);
        orderService.delivery(id);
        return Result.success();
    }
/**
 * 订单搜索
 * @param
 * @return
 */
    @GetMapping("/conditionSearch")
    @ApiOperation("订单搜索")
    public Result<PageResult> pageResult(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("订单搜索:{}", ordersPageQueryDTO);
        Page<OrderVO> ordersPage = orderService.pageAll(ordersPageQueryDTO);

        return Result.success(new PageResult(ordersPage.getTotal(), ordersPage.getResult()));
    }
    }
